import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutterhello/controller/Controller.dart';
import 'package:flutterhello/pages/chat_detail/chat_detail.dart';
import 'package:flutterhello/pages/three/widgets/chat_card.dart';
import 'package:get/get.dart';

class GroupChat extends StatelessWidget {
  final controller = Get.put(Controller());
  @override
  Widget build(BuildContext context) {
    return GetBuilder<Controller>(builder: (controller) {
      if (controller.allGroup.length != 0) {
        return EasyRefresh.custom(
          onRefresh: () {
            controller.connection();
          },
          slivers: <Widget>[
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (BuildContext context, int index) {
                  return ChatCard(
                    info: controller
                        .allGroup[controller.allGroup.length - index - 1],
                    showMsg: controller.chatsMap[controller.allGroup[
                                    controller.allGroup.length - index - 1]
                                ['id']] !=
                            null
                        ? controller
                            .chatsMap[controller.allGroup[
                                controller.allGroup.length - index - 1]['id']]
                            .last
                        : new MessageEntity(msg: ''),
                  );
                },
                childCount: controller.allGroup.length,
              ),
            )
          ],
        );
      } else {
        return Container();
      }
    });
  }
}
